<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 300px;
        height: 300px;
        background-color: blue;
      }
      .son {
        width: 150px;
        height: 150px;
        background-color: red;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>事件修饰符</h2>
      <!-- .stop就是事件修饰符，阻止事件冒泡 -->
      <div class="father" @click="fatherClick">
        <div class="son" @click.stop="sonClick"></div>
      </div>

      <hr />

      <!-- .prevent表示阻止默认行为 -->
      <form @submit.prevent="submit">
        <input type="text" />
        <input type="submit" />
      </form>

      <hr />

      <h2>按键修饰符</h2>
      <!-- 在vue2里面按键修饰符既可以 .13 也可以使用 .enter -->
      <!-- 在vue3里面按键修饰符既只可以使用 .enter -->
      <input type="text" v-on:keyup.enter="handleKeyUp" />
    </div>

    <!-- 
      事件修饰符
      .stop √
      .prevent √
      .self
      .capture
      .once
      .passive
     -->

    <!-- 
      按键修饰符
      .enter √
      .tab
      .delete (捕获“Delete”和“Backspace”两个按键)
      .esc
      .space
      .up
      .down
      .left
      .right
      -->

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {};
        },
        methods: {
          fatherClick() {
            console.log("fatherClick");
          },
          sonClick(e) {
            // e.stopPropagation();
            console.log("sonClick");
          },
          submit() {
            console.log("表单提交了");
          },
          handleKeyUp(e) {
            // if (e.keyCode === 13) {
            //   console.log(e.target.value);
            // }
            // if (e.key === "Enter") {
            //   console.log(e.target.value);
            // }
            console.log(e.target.value);
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
